package com.yelobblog.yelobblog.common.untils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Date;
import java.util.Map;

public class jwt {
    private static final String JWT_SECRET = "pepepepe";

    public static String getToken(Map<String,Object> claims) {
        return JWT.create()
                .withClaim("claims", claims)
                .withExpiresAt(new Date(System.currentTimeMillis() + 1000L * 60 * 60 * 24 * 30))
                .sign(Algorithm.HMAC256(JWT_SECRET));
    }

    public static Map<String,Object> parseToken(String token){
        return JWT.require(Algorithm.HMAC256(JWT_SECRET)).
                build().
                verify(token).getClaim("claims").
                asMap();
    }
}
